# 设置CMake的最小版本要求
cmake_minimum_required(VERSION 3.10)

# 设置项目名称和版本
project(GPSDataLink VERSION 1.0)

# 设置平台宏
if(WIN32)
	add_definitions(-DPLATFORM_WINDOWS)
elseif(UNIX AND NOT APPLE)
	add_definitions(-DPLATFORM_LINUX)
endif()

# 设置C++标准
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# 尝试找到Mysql库
find_path(MYSQL_INCLUDE_DIR mysql.h)
find_library(MYSQL_LIBRARY NAMES mysqlclient libmysql)

if(MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
	message(STATUS "MySQL found")
	include_directories(${MYSQL_INCLUDE_DIR})
else()
	message(STATUS "MySQL not found set path myself")
	if(WIN32)
		set(MYSQL_INCLUDE_DIR "C:/Program Files/MySQL/MySQL Server 8.0/include")
		set(MYSQL_LIBRARY "C:/Program Files/MySQL/MySQL Server 8.0/lib/libmysql.lib")
	elseif(UNIX AND NOT APPLE)
		set(MYSQL_INCLUDE_DIR "/usr/include/mysql")
	endif()
	include_directories(${MYSQL_INCLUDE_DIR})
endif()

# 定义源文件
set(SOURCE_FILES src/Mysql.cpp)

# 添加可执行文件
add_executable(GPSDataLink ${SOURCE_FILES})

# 链接mysql库
if(WIN32)
	target_link_libraries(GPSDataLink ${MYSQL_LIBRARY})
endif()
